﻿// (c)2010 David Schwarz (david.schwarz@live.com)
// This file is licensed under GNU GPL v2 license, see more at http://www.gnu.org/licenses/gpl-2.0.html
namespace vKapse.DDTool.Core
{

	#region Using

	using System;
	using System.Collections.Generic;
	using System.Text;

	#endregion Using

	/// <summary>
	/// Třída pro asociaci spouštěče s vizuálním objektem
	/// </summary>
	internal abstract class TriggerAssociationBase
	{

		#region Members

		private Type m_type;
		private Dictionary<object, TriggerBase> m_triggers;

		#endregion Members

		#region Constructor

		/// <summary>
		/// Konstruktor
		/// </summary>
		protected TriggerAssociationBase(Type type)
		{
			this.m_type = type;
			this.m_triggers = new Dictionary<object, TriggerBase>();
		}

		#endregion Constructor

		#region Properties

		/// <summary>
		/// Vrací asociovaný typ
		/// </summary>
		public Type Type
		{
			get
			{
				return this.m_type;
			}
		}

		#endregion Properties

		#region Methods

		protected void Add(TriggerBase trigger, object obj)
		{
			if(!this.m_triggers.ContainsKey(obj))
				this.m_triggers.Add(obj, trigger);
		}

		protected void Remove(object obj)
		{
			this.m_triggers.Remove(obj);
		}

		protected TriggerBase GetTrigger(object obj)
		{
			if (this.m_triggers.ContainsKey(obj))
			{
				return this.m_triggers[obj];
			}
			return null;
		}


		/// <summary>
		/// Registruje trigger
		/// </summary>
		/// <param name="trigger"></param>
		/// <param name="obj"></param>
		internal abstract void Register(TriggerBase trigger, object obj);

		internal abstract void Unregister(object obj);

		/// <summary>
		/// Metoda provede nastavení změn ve spouštěči
		/// </summary>
		/// <param name="trigger"></param>
		/// <param name="obj"></param>
		internal abstract void ApplyChanges(TriggerBase trigger, object obj);

		#endregion Methods


	}
}
